package com.gitee.theskyzero.data.redis;

import io.lettuce.core.ClientOptions;
import io.lettuce.core.cluster.ClusterClientOptions;
import io.lettuce.core.cluster.ClusterTopologyRefreshOptions;
import io.lettuce.core.resource.DefaultClientResources;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.redis.LettuceClientConfigurationBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnExpression(value = "false")
public class RedisCustomConfiguration {

    /**
     * LettuceConnectionConfiguration 提供扩展
     *
     * @return
     */
    @Bean
    @ConditionalOnExpression(value = "false")
    LettuceClientConfigurationBuilderCustomizer lettuceClientConfigurationBuilderCustomizer() {
        return clientConfigurationBuilder -> clientConfigurationBuilder
                .clientOptions(
                        ClusterClientOptions.builder()
                                .autoReconnect(true)
                                .topologyRefreshOptions(
                                        ClusterTopologyRefreshOptions.builder()
                                                .dynamicRefreshSources(true)
                                                .build()
                                )
                                .build()
                )
                .build();
    }

    /**
     * LettuceConnectionConfiguration 提供扩展
     *
     * @return
     */
    @Bean
    @ConditionalOnExpression(value = "false")
    DefaultClientResources clientResources() {
        return DefaultClientResources.builder()
                .ioThreadPoolSize(8)
                .build();
    }
}
